package liveData.migration.toPhoenix.util.partitionUtils;

import liveData.migration.toPhoenix.util.StringUtils;
import org.apache.flink.api.common.functions.Partitioner;
import org.apache.kafka.common.utils.Utils;

/**
 * @program: userPortrait
 * @description:
 * @author: sunteng
 * @create: 2020-08-21 13:37
 **/
public class UidPartitioner implements Partitioner<String> {
    @Override
    public int partition(String key, int numPartitions) {
        if(StringUtils.isNotEmpty(key)){
            return Utils.toPositive(Utils.murmur2(key.getBytes())) % numPartitions;
        }
        return 0;
    }
}
